fix(hw_support): Fix crash when reconfiguring flash from 40 to 80 MHz (IDFGH-16831) #17905
+17
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
7549d08 moved
call_start_cpu0from IRAM to flash. Unfortunately, this included code that reconfigures the flash if the application’s flash speed differs from the bootloader’s flash speed.When an application with a flash speed of 80 MHz is started from a bootloader with a flash speed of 40 MHz, it will crash shortly after
bootloader_flash_cs_timing_config()returns. This is caused by reading instructions from flash while the flash is being reconfigured to the higher speed, which results in corrupt instruction data being read.Possible crashes to encounter:
movi.n a8, 1.As this code runs early during start-up, the device will be stuck in an infinite reboot loop. This means that loading an application built from the 5.5.1 release via OTA onto a device that contains an older bootloader with a slower flash speed will brick the device.
This PR fixes the problem by moving the flash configuration calls into a helper function that is placed in IRAM. The call to increase the flash clock has also been moved so that the GPIO settings and SPI dummy cycles are set to safe values before the clock is increased.
The commit that introduces the problem has already been backported to 5.5.1 as e1faf67, so this fix will also have to be backported.
Note
Moves ESP32 flash config sequence into IRAM helper
configure_flash()and invokes it during early init (when PSRAM HW init is disabled) to avoid executing from flash while reconfiguring.configure_flash()to adjust flash GPIO, dummy cycles, clock, and CS timing safely.bootloader_flash_*calls withconfigure_flash(&fhdr)in early init when!CONFIG_SPIRAM_BOOT_HW_INIT.CONFIG_IDF_TARGET_ESP32; no behavior change for other targets.Written by Cursor Bugbot for commit 7565d53. This will update automatically on new commits. Configure here.